﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static LiWi.Shell;

namespace LiWi
{
    public partial class 点动模式 : Form
    {
        public 点动模式()
        {
            InitializeComponent();
        }
        int[] axislist = { 0 };
        //反转
        private void btn_JogReduce_MouseDown(object sender, MouseEventArgs e)
        {
            axislist[0] = Convert.ToInt32(num_AxisNum.Value);
            PMC_Base(Data.handle, 1, axislist);
            PMC_SetUnits(Data.handle, axislist[0], Convert.ToInt32(num_uint.Value));
            PMC_SetSpeed(Data.handle, axislist[0], Convert.ToUInt32(num_Speed.Value));
            PMC_SetAccel(Data.handle, axislist[0], Convert.ToInt32(num_accel.Value));
            PMC_SetDecel(Data.handle, axislist[0], Convert.ToInt32(num_deccel.Value));
            JOGSport(axislist, -1);
        }

        private void btn_JogReduce_MouseUp(object sender, MouseEventArgs e)
        {
            PMC_Single_Cancel(Data.handle, axislist[0], 3);
        }

        //正向
        private void btn_JogAdd_MouseDown(object sender, MouseEventArgs e)
        {
            axislist[0] = Convert.ToInt32(num_AxisNum.Value);
            PMC_Base(Data.handle, 1, axislist);
            PMC_SetUnits(Data.handle, axislist[0], Convert.ToInt32(num_uint.Value));
            PMC_SetSpeed(Data.handle, axislist[0], Convert.ToUInt32(num_Speed.Value));
            PMC_SetAccel(Data.handle, axislist[0], Convert.ToInt32(num_accel.Value));
            PMC_SetDecel(Data.handle, axislist[0], Convert.ToInt32(num_deccel.Value));
            JOGSport(axislist, 1);
        }

        private void btn_JogAdd_MouseUp(object sender, MouseEventArgs e)
        {
            PMC_Single_Cancel(Data.handle, axislist[0], 3);
        }

        /// <summary>
        /// 持续运动
        /// </summary>
        /// <param name="iaxis">轴号</param>
        /// <param name="flag">1：正向，-1：负向</param>
        public void JOGSport(int[] axisList, int flag)
        {
            PMC_Base(Data.handle, 1, axisList);
            PMC_Single_Vmove(Data.handle, axisList[0], flag);           //连续运动：1正向，-1负向                
        }
    }
}
